package com.example.myapplication3

import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class MainActivity4 : AppCompatActivity() {
    private lateinit var textView: TextView
    var count=0
        set(value){
            field=value
            textView.text="Count:$value"
        }
    val  MainTag="MainActivity4"
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main4)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        val button5=findViewById<Button>(R.id.button5)
        button5.setOnClickListener {
            finish()
        }
        textView = findViewById( R.id.textView)
        val button = findViewById<Button>( R.id.button)
        button.setOnClickListener {
            count++
            textView.text = "Count:$count"
        }
        Log.d(MainTag,  "onCreate")
    }

    override fun onStart() {
        super.onStart()
        Log.d(MainTag,  "onStart")
    }

    override fun onResume() {
        super.onResume()
        Log.d(MainTag,  "onResume")
    }

    override fun onPause() {
        super.onPause()
        Log.d(MainTag,  "onPause")
    }

    override fun onStop() {
        super.onStop()
        Log.d(MainTag,  "onStop")
    }

    override fun onRestart() {
        super.onRestart()
        Log.d(MainTag,  "onRestart")
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.d(MainTag, "onDestroy")
    }

    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)
        Log.d(MainTag,  "onSaveInstanceState")
        outState.putInt("count", count)
    }

    override fun onRestoreInstanceState(savedInstanceState: Bundle) {
        super.onRestoreInstanceState(savedInstanceState)
        Log.d(MainTag,  "onRestoreInstanceState")
        count = savedInstanceState.getInt( "count")

    }
}